package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark66Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark66 extends BaseMark {

    LayoutWatermark66Binding binding;

    public Mark66(@NonNull Context context) {
        super(context);
    }

    public Mark66(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark66(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark66Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.group.getChildCount();
            for (int i = 4; i < n; i++) {
                binding.group.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark66Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    private void setTime() {
        long time = getTime();
        if (time > 0) {
            String str = new SimpleDateFormat("HH:mm:ss").format(time);
            String[] ss = str.split(":");
            binding.tvHour.setText(ss[0]);
            binding.tvMinute.setText(ss[1]);
            binding.tvSec.setText(ss[2]);
            setWeek(binding.tvWeek);
        }
    }

    @Override
    public void update() {
        setText(binding.tvHour, "time66");
        setTime();

        setText(binding.tvAddress, "didian66", binding.layoutAddress);
        setText(binding.tvWeather, "weather66", binding.layoutWeather);
        setText(binding.tvLola, "jingwei66", binding.layoutLola);
        setText(binding.tvRemark, "beizhu66", binding.layoutRemark);
        setText(binding.tvPeople, "name66", binding.layoutPeople);
        setText(binding.tvMk, "tip66", binding.layoutMk);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time66", "时间", true));
        list.add(new EditItem("didian66", "地点"));
        list.add(new EditItem("weather66", "天气"));

        list.add(new EditItem("jingwei66", "经纬度"));
        list.add(new EditItem("beizhu66", "备注"));

        list.add(new EditItem("name66", "昵称"));
        list.add(new EditItem("tip66", "提示语"));


        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime();
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.layout1, binding.tvWeek);
            } else {
                hideView(binding.layout1, binding.tvWeek);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
